package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysStock;
import com.ruoyi.system.service.ISysStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存详细Controller
 * 
 * @author ruoyi
 * @date 2025-04-25
 */
@Api("库存详细")
@RestController
@RequestMapping("/system/stock")
public class SysStockController extends BaseController
{
    @Autowired
    private ISysStockService sysStockService;

    /**
     * 查询库存详细列表
     */
    @ApiOperation("查询库存详细列表")
    // @PreAuthorize("@ss.hasPermi('system:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysStock sysStock)
    {
        startPage();
        List<SysStock> list = sysStockService.selectSysStockList(sysStock);
        return getDataTable(list);
    }

    /**
     * 导出库存详细列表
     */
    @ApiOperation("导出库存详细列表")
    // @PreAuthorize("@ss.hasPermi('system:stock:export')")
    @Log(title = "库存详细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysStock sysStock)
    {
        List<SysStock> list = sysStockService.selectSysStockList(sysStock);
        ExcelUtil<SysStock> util = new ExcelUtil<SysStock>(SysStock.class);
        util.exportExcel(response, list, "库存详细数据");
    }

    /**
     * 获取库存详细详细信息
     */
    @ApiOperation("获取库存详细详细信息")
    // @PreAuthorize("@ss.hasPermi('system:stock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysStockService.selectSysStockById(id));
    }

    /**
     * 新增库存详细
     */
    @ApiOperation("新增库存详细")
    // @PreAuthorize("@ss.hasPermi('system:stock:add')")
    @Log(title = "库存详细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysStock sysStock)
    {
        return toAjax(sysStockService.insertSysStock(sysStock));
    }

    /**
     * 修改库存详细
     */
    @ApiOperation("修改库存详细")
    // @PreAuthorize("@ss.hasPermi('system:stock:edit')")
    @Log(title = "库存详细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysStock sysStock)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        sysStock.setUpdateBy(user.getUserId() + "");
        return toAjax(sysStockService.updateSysStock(sysStock));
    }

    /**
     * 删除库存详细
     */
    @ApiOperation("删除库存详细")
    // @PreAuthorize("@ss.hasPermi('system:stock:remove')")
    @Log(title = "库存详细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysStockService.deleteSysStockByIds(ids));
    }
}
